from pymongo import MongoClient

def user_gain(username):
    # 连接到MongoDB（确保MongoDB服务已在本地运行）
    client = MongoClient("mongodb://192.168.168.110:27017/")

    # 选择数据库
    db = client['data']

    # 查询username对应的所有card数据
    cards = db.usercard.find({"username": username}, {"card": 1})

    allpai = []
    for entry in cards:
        allpai.append(entry.get("card"))  # 应该使用entry而不是user

    # 打印结果
    print(f"本场您的牌为:", allpai)

    # 关闭MongoDB连接
    client.close()

if __name__ == "__main__":
    username = "lishi"
    user_gain(username)
